package com.wty.design.creational.simpleFactory;

import java.lang.reflect.InvocationTargetException;

public class VideoFactory {

//    //版本一，添加课程时需要修改
//    public Video getVideo(String videoName){
//        Video video = null;
//        if (videoName.equals("java")){
//            video= new javaVideo();
//        }
//        if (videoName.equals("python")){
//            video= new PythonVideo();
//        }
//        return video;
//    }

    //版本2，通过类加载，添加课程时无需修改工厂类

    public static Video getVideo(Class clazz){
        Video video=null;
        try {
            video= (Video) clazz.getConstructor().newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
        return video;
    }
}
